package com.atguigu.gmall.common.minio.config;

import com.atguigu.gmall.common.minio.service.OSSService;
import com.atguigu.gmall.common.minio.service.impl.OSSServiceImpl;
import io.minio.MinioClient;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2024/9/7 0:08
 */
@EnableConfigurationProperties(MinioProperties.class)
//开启MinioProperties和配置文件绑定
//MinioProperties放入容器
@Configuration
public class MinioConfig {
    @Autowired
    MinioProperties minioProperties;
    @Bean
    public MinioClient getMinioClient() throws InvalidPortException, InvalidEndpointException {
        MinioClient minioClient = new MinioClient(minioProperties.getEndpoint(), minioProperties.getAccessKey(),minioProperties.getSecretKey());
        return minioClient;
    }
    @Bean
    public OSSService ossService(){
        return new OSSServiceImpl();
    }
}
